package test3_11;

import java.util.Arrays;

public class Homework5_12_combination {
    public static void main(String[] args) {
        /*
        已知有数组String[] names= {“关羽”,“张飞”,“赵云”,“马超”,“黄忠”,“吕布”};
        在数据中任意选出三名成员，一共有多少种组合？
        编写将所有组合输出，并输出组合的数量。
         */

        //初始化sum用来计算组合个数
        int sum = 0;
        //初始化数组用于存储每种组合的成员
        String[] combination = new String[3];
        String[] names = {"关羽", "张飞", "赵云", "马超", "黄忠", "吕布" };
        //用嵌套循环依次判断结果
        for (int i = 0; i < names.length; i++) {
            combination[0] = names[i];
            for (int j = i + 1; j < names.length; j++) {
                combination[1] = names[j];
                for (int k = j + 1; k < names.length; k++) {
                    combination[2] = names[k];
                    System.out.println(Arrays.toString(combination));
                    sum += 1;
                }
            }
        }
        System.out.println("共" + sum + "种");
    }
}
